import time

from util.DbUtils import Tool

t = Tool()


def log(func):
    def wrapper(self,index, money):
        func(self,index, money)
        times = str(time.strftime("%F %T"))
        user_list = t.select("select * from userinfo")
        uinfo = user_list[index]
        uname = uinfo[0]
        balance = uinfo[2]
        history = "变更{}元成功,剩余金额为{}元".format(money, balance)
        print(uname,history)
        t.update("insert into waterrun values('{}','{}','{}')".format(uname, history, times))

    return wrapper